//
//  UIGridViewCell.m
//  foodling2
//
//  Created by Tanin Na Nakorn on 3/6/12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "UIGridViewCell.h"


@implementation UIGridViewCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setBackgroundColor:(UIColor *)backgroundColor imageName:(NSString *)imageName title:(NSString *)title{
    self.adjustsImageWhenHighlighted = NO;
    self.backgroundColor = backgroundColor;
    NSString *selectedImageName = [NSString stringWithFormat:@"%@_focus",
                                   [imageName stringByDeletingPathExtension]];
    [self setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [self setImage:[UIImage imageNamed:selectedImageName] forState:UIControlStateHighlighted];
    [self setTitle:title forState:UIControlStateNormal];
    [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.titleLabel.font = [UIFont systemFontOfSize:14.0];
}


- (void)setBackgroundName:(NSString *)backgroundName imageName:(NSString *)imageName title:(NSString *)title
{
    self.adjustsImageWhenHighlighted = NO;
    self.backgroundColor = [UIColor clearColor];
    NSString *selectedImageName = [NSString stringWithFormat:@"%@_focus",
                                 [imageName stringByDeletingPathExtension]];
    [self setBackgroundImage:[UIImage imageNamed:backgroundName] forState:UIControlStateNormal];
    [self setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [self setImage:[UIImage imageNamed:selectedImageName] forState:UIControlStateSelected];
    [self setTitle:title forState:UIControlStateNormal];
    self.titleLabel.font = [UIFont systemFontOfSize:14.0];
}

- (void) addSubview:(UIView *)v
{
	[super addSubview:v];
	v.exclusiveTouch = NO;
	v.userInteractionEnabled = NO;
}

- (void)setFrame:(CGRect)aFrame {
	[super setFrame:aFrame];
	[self setNeedsDisplay];
}

- (void)layoutSubviews {
	[super layoutSubviews];
	
	UIEdgeInsets imageInsets = UIEdgeInsetsMake(-20, 0, 0, -self.titleLabel.bounds.size.width);
    UIEdgeInsets titleInsets = UIEdgeInsetsMake(60, -self.imageView.image.size.width, 0, 0);
	self.imageEdgeInsets = imageInsets;
    self.titleEdgeInsets = titleInsets;
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect
 {
 // Drawing code
 }
 */


@end
